//
// Created by cjg on 2018/5/29.
// Copyright (c) 2018 chenjg. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CCAFHTTPSessionManager.h"
#import "CCNetModel.h"

#define KCCRequestTool [CCRequestTool shared]

typedef void(^RequestFinishBlock)(BOOL success, id responseObject, NSString *json, NSURLSessionDataTask *task);

@interface CCRequestTool : NSObject

/*默认请求头*/
@property(nonatomic, strong) NSDictionary *header;
/*超时时间, 默认15秒*/
@property(nonatomic, assign) NSTimeInterval timeout;
/*网络请求session会话管理*/
@property(nonatomic, strong, readonly) CCAFHTTPSessionManager *sessionManager;
/*设置后如果url请求url是http开头则无效, 若不是实际URL为则baseURL+URL参数*/
@property(nonatomic, strong) NSString *baseURL;

+ (instancetype)shared;


/**
 不带HEADER

 @param url 请求地址
 @param type 请求类型
 @param params 参数
 @param finish
 @return 
 */
- (NSURLSessionDataTask *)requestWithURL:(NSString *)url
                                    type:(RequestType)type
                                  params:(id)params
                                  finish:(void (^)(BOOL success, id responseObject, NSString *json, NSURLSessionDataTask *task))finish;


/**
 带HEADER

 @param url 请求地址
 @param type 请求类型
 @param params 参数
 @param header 请求头
 @param upProgress
 @param downloadProgress
 @param finish
 @return
 */
- (NSURLSessionDataTask *)requestWithURL:(NSString *)url
                                    type:(RequestType)type
                                  params:(id)params
                                  header:(NSDictionary *)header
                              upProgress:(void (^)(NSProgress *upProgress))upProgress
                            downProgress:(void (^)(NSProgress *downloadProgress))downloadProgress
                                  finish:(void (^)(BOOL success, id responseObject, NSString *json, NSURLSessionDataTask *task))finish;

- (NSURLSessionDataTask *)formDataWithURL:(NSString *)url
                                   params:(id)params
                                   header:(NSDictionary *)header
                                   models:(NSArray<CCNetModel *> *)models
                               upProgress:(void (^)(NSProgress *upProgress))upProgress
                                   finish:(void (^)(BOOL success, id responseObject, NSString *json, NSURLSessionDataTask *task))finish;

- (NSURLSessionDownloadTask *)downLoadWithURL:(NSString *)url
                                      fileURL:(NSString *)fileURL
                                     progress:(void (^)(NSProgress *downloadProgress))downloadProgressBlock
                            completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;

//TODO: 断点下载, 后台下载

@end
